package com.itlong.cloud.operate.service.impl;

import com.itlong.cloud.POJO.DTO.operate.OperateCheckAccountByPageDTO;
import com.itlong.cloud.POJO.VO.operate.OperateCheckAccountGetPageVO;
import com.itlong.cloud.operate.dao.ICheckAccountDao;
import com.itlong.cloud.operate.service.ICheckAccountService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 * 运营-财务展示对账服务实现类.
 * </desc>
 *
 * @createDate 2018/9/19
 */
@Service
public class CheckAccountServiceImpl implements ICheckAccountService{

    @Autowired
    ICheckAccountDao iCheckAccountDao;

    /**
     * <desc>
     *      根据条件分页查询自动出账的出入列表
     * <desc/>
     * @param   checkAccountByPageDTO 查询条件
     * @return page
     * @author Juguang.S
     * @createDate 2018/9/19
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page<OperateCheckAccountGetPageVO> getCheckDiffInfoByPage(OperateCheckAccountByPageDTO checkAccountByPageDTO) throws Exception {
        Map<String,Object> params = SqlUtil.convertBeanToMapParams(checkAccountByPageDTO);
        Page<OperateCheckAccountGetPageVO> page = new Page<>();
        page.getPage().setPageSize(checkAccountByPageDTO.getPageSize());
        page.getPage().setCurrentPage(checkAccountByPageDTO.getCurrentPage());
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize", page.getPage().getPageSize());
        List<OperateCheckAccountGetPageVO> datas = iCheckAccountDao.getCheckDiffInfoByPage(params);
        page.setRows(datas,iCheckAccountDao.getCheckDiffInfoCount(params));
        return page;
    }

    /**
     * <desc>
     *      根据ID查询其备注和订单状态
     * <desc/>
     *
     * @param orderDiffId
     * @return
     * @author Juguang.S
     * @createDate 2018-09-19
     */
    @Override
    public Map<String,Object> getCheckInfo(String orderDiffId) {
        return iCheckAccountDao.getCheckInfo(orderDiffId);
    }

    /**
     * <desc>
     *      根据ID修改其备注和订单状态
     * <desc/>
     *
     * @param orderDiffId id
     * @param remark 备注
     * @param diffOrderStatus 订单状态
     * @return
     * @author Juguang.S
     * @createDate 2018-09-19
     */
    @Override
    public void updateStatus(String orderDiffId,String diffOrderStatus,String remark,String myUserName) {
        iCheckAccountDao.updateStatus(orderDiffId,diffOrderStatus,remark,myUserName);
    }

    /**
     * <desc>
     *      根据条件查询出所有出入信息
     * <desc/>
     *
     * @param checkAccountByPageDTO 条件
     * @return
     * @author Juguang.S
     * @createDate 2018-09-19
     */
    @Override
    public List<OperateCheckAccountGetPageVO> getDiffInfo(OperateCheckAccountByPageDTO checkAccountByPageDTO) throws Exception {
        Map<String,Object> params = SqlUtil.convertBeanToMapParams(checkAccountByPageDTO);
        return iCheckAccountDao.getCheckDiffInfoForExport(params);
    }
}